<template>
	<view>
		<cu-custom bgColor="bg-top" :isBack="true">
			<block slot="content">站点污染物</block>
		</cu-custom>
		<view class="cu-form-group">
			<view class="title">日期选择</view>
			<picker mode="date" :value="date" start="2019-09-01" end="2020-09-01" @change="DateChange">
				<view class="picker">
					{{date}}
				</view>
			</picker>
		</view>
		<!-- <view class="cu-form-group">
			<view class="title">开始时间</view>
			<picker mode="time" :value="starttime" start="09:01" end="21:01" @change="startTimeChange">
				<view class="picker">
					{{starttime}}
				</view>
			</picker>
		</view>
		<view class="cu-form-group">
			<view class="title">结束时间</view>
			<picker mode="time" :value="endtime" start="09:01" end="21:01" @change="endTimeChange">
				<view class="picker">
					{{endtime}}
				</view>
			</picker>
		</view>-->
		
		<m-table :data="datas" :column="column"/>
	</view>
</template>

<script>
	import Util from '@/utils/util.js'
	import {formatDateDay} from '@/utils/datetime.js'
	export default {
		components: {
		    
		},
		data() {
			return {
				starttime: '00:00',
				endtime: '23:59',
				date: '',
				params:{},
				datas:[],
				column:{},
			};
		},
		onLoad(e) {
			//加载站点污染物
			if(e.polls){
				this.column = {}
				this.params.polls = e.polls
				this.column.name=e.pollName+'\n'+e.pollUnit
				this.column.code='avgCB'+e.polls
			}
			if(e.mn){
				this.params.mn = e.mn
			}
			this.init();
			this.getData();
		},
		methods:{
			DateChange(e) {
				this.date = e.detail.value
				this.getData()
			},
			startTimeChange(e) {
				this.starttime = e.detail.value
			},
			endTimeChange(e) {
				this.endtime = e.detail.value
			},
			getData(){
				this.params.start_time = this.date + " " + this.starttime + ":00"
				this.params.end_time = this.date + " " + this.endtime + ":59"
				Util.request('/monitor/pollMinData/list', this.params, 'GET').then(res=>{
					 this.datas = []
					 res.data.data.map(item => {
						let rtd = ''
						if(typeof item[this.column.code]=='undefined'){
							rtd = ''
						}else{
							rtd = item[this.column.code]
						}
						this.datas.push({'dateTime':item.dateTime,'rtd':rtd})
					})
				}).catch(()=>{
					//联网失败, 结束加载
				})
			},
			//初始化时间
			init() {
				let date = formatDateDay(new Date());
				// let hour = new Date().getHours()+1;
				
				
				// this.starttime = (hour-2)+ ':00',
				// this.endtime = hour+ ':59',
				this.date =  date
			}
		}
	}
</script>

<style lang="scss">

</style>
